import axios from 'axios'
import { surl } from '@/utils/common.js'

const request = axios.create({
    baseURL: surl,
    timeout: 10000
})


request.interceptors.request.use(function (config) {
    if(sessionStorage.getItem('user')){
        const user = JSON.parse(sessionStorage.getItem('user'))
        config.headers.Authorization = `Bearer ${user.token}`;
    }
    return config;
  }, function (error) {
    return Promise.reject(error);
  });


request.interceptors.response.use(function (response) {
    return response.data;
  }, function (error) {
    return Promise.reject(error);
  });

export default request;